#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>

int main()
{
  //close(1);
  
  int fd =open("log.txt",O_RDONLY );
  //int fd =open("log.txt",O_WRONLY | O_CREAT | O_APPEND );
  //int fd =open("log.txt",O_WRONLY | O_CREAT | O_APPEND );
  if(fd<0)
  {
    perror("open");
    return 1;
  }
  dup2(fd,0);

  char line[64];
  while(fgets(line,sizeof line,stdin))
  {
    printf("%s\n",line);
  }
  //printf("打开文件成功,fd: %d\n",fd);
  //fprintf(stdout,"打开文件成功 fd:%d\n",fd);
  
  //fflush(stdout);
  close(fd);


  return 0;
}
